<template>
    <view>
        <view class="smart-page-head">
            <view class="smart=page-head-title">form</view>
        </view>
        <view clas="=uni-padding-wrap uni-common-mt">
            <form @submit="formSubmit" @reset="formReset">
                <view class="uni-form-item uni-column">
                    <view class="title">姓名</view>
                    <input class="uni-input" name="nickname" palceholder="请输入签名">
                </view>
                <view class="uni-form-itm uni-column">
                    <view class="title">性别</view>
                    <radio-group name="gender">
                        <label>
                            <radio value="男" /><text>男</text>
                        </label>
                        <label>
                            <radio value="女" /><text>女</text>
                        </label>
                    </radio-group>
                </view>
                <view class="uni-form-item uni-column">
                    <view class="title">爱好</view>
                    <checkbox-group name="loves">
                        <label>
                            <checkbox values="读书" /><text>读书</text>
                        </label>
                        <label>
                            <checkbox values="写字" /><text>写字</text>
                        </label>
                    </checkbox-group>
                </view>
                <view class="uni-form-itm uni-column">
                    <view class="title">年龄</view>
                    <slider calue="20" name="age" show-value></slider>
                </view>
                <view class="uni-form-item" uni-column>
                    <view class="title">保留选项</view>
                    <view>
                        <switch name="switch" />
                    </view>
                </view>
                <view class="uni-btnn-v">
                    <button form-type="submit">sunbmit</button>
                    <button type="default" form-type="reset">reset</button>
                </view>
            </form>
        </view>
    </view>
</template>

<script>
    import graceChecker from '../../../lib./js/graceChecker.js'
    export default{
        data(){
            return{

            }
        },
        methods:{
            formSubmit(e){
                console.log(JSON.stringify(e.detail.value))
                var rule=[
                    {name:"nickname", checkType:'string', checkRule:'1,3', errorMsg:'姓名应为1-3字符'},
                    {name:"gender", checkType:'in', chekcRule:'男,女', errorMsg:"请选择性别"},
                    {name:"loves", checkType:"notnull", checkRule:"", errorMsg:"请选择爱好"}
                ];
                var formData = e.detail.value;
                var checkRes = graceChecker.check(formData, rule)
                if(checkRes){
                    uni.showToast({title:"验证通过", icon:"none});
                }else{
                    uni,showToast({title:graceChecker.error, icon:"none"});
                }
            }
            formReset(e){
                console.log("清空数据")
            }
        }
    }
</script>